package pl.edu.pw.polygen.security;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class User implements UserDetails {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 7442066834578684274L;

	private Long id;
	private String login;
	private String password;
	private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

	public User() {
		super();
	}

	public User(Long id, String login, String password, String[] authorities) {
		super();
		this.id = id;
		this.login = login;
		this.password = password;
		if (authorities != null) {
			for (String authority : authorities) {
				addAuthority(authority);
			}
		}
	}

	@Override
	public String getUsername() {
		return login;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return authorities;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void addAuthority(String authority) {
		this.authorities.add(new Authority(authority));
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}
